﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using Meqs.Entity;
using System.Web.UI.MobileControls;
using System.Collections.Generic;

public partial class School_Report_UserDistribution : System.Web.UI.Page
{
    protected IList<ExamSubjecySchool2> subj = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string examid = SchoolCookie.ExamID.ToString() ;
            string classtype = SchoolCookie.ExamClassType.ToString();
            string examgrade = SchoolCookie.ExamGrade.ToString();


            //?ExamId=1&ClassType=0&ExamGrade=1
            //string examid = "1";
            //string classtype = "0";
            //string examgrade = "1";
            int temp = -1;
            int.TryParse(examid, out temp);
            ExamId = temp;

            temp = -1;
            int.TryParse(classtype, out temp);
            ClassType = temp;

            temp = -1;
            int.TryParse(examgrade, out temp);
            ExamGrade = temp;


            if (ExamId != -1 && ClassType != -1 && ExamGrade != -1)
            {
                subj = Container<Meqs.Logic.Interface.IExamSubjecySchoolLogic>.Instance.GetExamCause(examId, classType,CommonScore.GetSchoolMark);
            }
            
        }
    }
    [WebMethod]//KindSettingsEducation[] kinds, int examid, int subjectid
    public static int[] SaveUsersSets(DistributionSettingsSchool[] kinds, int[] deleteids, int examid, int subjectid, int classtype)
    {
        List<int> tempids = new List<int>();
        foreach (DistributionSettingsSchool k in kinds)
        {
            k.ExamID = examid;
            k.SubjectID = subjectid;
            k.Type = classtype;
            k.SchoolMark = CommonScore.GetSchoolMark;
            if (k.RID == -1)
            {
                int i = Container<Meqs.Logic.Interface.IDistributionSettingsSchoolLogic>.Instance.Create(k);
                tempids.Add(i);
            }
            else
            {
                Container<Meqs.Logic.Interface.IDistributionSettingsSchoolLogic>.Instance.Update(k);
                tempids.Add(k.RID);
            }
        }
        Hashtable ht = null;
        foreach (int i in deleteids)
        {
            ht = new Hashtable();
            ht.Add("SchoolMark",CommonScore.GetSchoolMark);
            ht.Add("RID",i);
            Container<Meqs.Logic.Interface.IDistributionSettingsSchoolLogic>.Instance.DeleteById(ht);
        }

        int[] ids = new int[tempids.Count];
        for (int i = 0; i < tempids.Count; i++)
        {
            ids[i] = tempids[i];
        }
        ht = new Hashtable();
        ht.Add("SchoolMark", CommonScore.GetSchoolMark);
        ht.Add("TestID", examid);
        Container<Meqs.Logic.Interface.IDistributionSettingsSchoolLogic>.Instance.UpdateCatch(ht);
        return ids;
    }
    protected void btnBind_Click(object sender, EventArgs e)
    {
        int subjId = Convert.ToInt32(typeid.Text);
        int iclasstype = Convert.ToInt32(classtype.Text);
        int iexamgrade = Convert.ToInt32(grade.Text);
        int myexamid = Convert.ToInt32(examid.Text);
        Hashtable ht = new Hashtable();
        ht.Add("SubjectID", subjId);
        ht.Add("Type", iclasstype);
        ht.Add("Grade", iexamgrade);
        ht.Add("ExamID", myexamid);
        ht.Add("SchoolMark", CommonScore.GetSchoolMark);
        IList<DistributionSettingsSchool> newList = Container<Meqs.Logic.Interface.IDistributionSettingsSchoolLogic>.Instance.FindAll(ht);
        Repeater1.DataSource = newList;
        Repeater1.DataBind();
    }

    //[WebMethod]//KindSettingsEducation[] kinds, int examid, int subjectid
    //public static int SaveSettings()
    //{
    //    int[] ids = new int[4] { 1, 2, 3, 4 };
    //    return 0;
    //}
    #region 考试号
    protected int examId = 0;
    public int ExamId
    {
        get { return examId; }
        set { examId = value; examid.Text = examId.ToString(); }
    }
    #endregion
    #region 考试文理分科
    protected int classType = 0;
    public int ClassType
    {
        get { return classType; }
        set { classType = value; classtype.Text = classType.ToString(); }
    }
    #endregion

    #region 年级
    protected int examgrade = 0;
    public int ExamGrade
    {
        get { return examgrade; }
        set { examgrade = value; grade.Text = examgrade.ToString(); }
    }
    #endregion
}
